package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysOwnerCars;
import com.ruoyi.system.service.ISysOwnerCarsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人车映射Controller
 * 
 * @author ruoyi
 * @date 2022-05-11
 */
@RestController
@RequestMapping("/system/ownercars")
public class SysOwnerCarsController extends BaseController
{
    @Autowired
    private ISysOwnerCarsService sysOwnerCarsService;

    /**
     * 查询人车映射列表
     */
    @PreAuthorize("@ss.hasPermi('system:ownercars:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOwnerCars sysOwnerCars)
    {
        startPage();
        List<SysOwnerCars> list = sysOwnerCarsService.selectSysOwnerCarsList(sysOwnerCars);
        return getDataTable(list);
    }

    /**
     * 导出人车映射列表
     */
    @PreAuthorize("@ss.hasPermi('system:ownercars:export')")
    @Log(title = "人车映射", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOwnerCars sysOwnerCars)
    {
        List<SysOwnerCars> list = sysOwnerCarsService.selectSysOwnerCarsList(sysOwnerCars);
        ExcelUtil<SysOwnerCars> util = new ExcelUtil<SysOwnerCars>(SysOwnerCars.class);
        util.exportExcel(response, list, "人车映射数据");
    }

    /**
     * 获取人车映射详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ownercars:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysOwnerCarsService.selectSysOwnerCarsById(id));
    }

    /**
     * 新增人车映射
     */
    @PreAuthorize("@ss.hasPermi('system:ownercars:add')")
    @Log(title = "人车映射", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysOwnerCars sysOwnerCars)
    {
        return toAjax(sysOwnerCarsService.insertSysOwnerCars(sysOwnerCars));
    }

    /**
     * 修改人车映射
     */
    @PreAuthorize("@ss.hasPermi('system:ownercars:edit')")
    @Log(title = "人车映射", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOwnerCars sysOwnerCars)
    {
        return toAjax(sysOwnerCarsService.updateSysOwnerCars(sysOwnerCars));
    }

    /**
     * 删除人车映射
     */
    @PreAuthorize("@ss.hasPermi('system:ownercars:remove')")
    @Log(title = "人车映射", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysOwnerCarsService.deleteSysOwnerCarsByIds(ids));
    }
}
